package com.ganzalang.gmall.learning.netty.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.IntBuffer;

/**
 * @author Ganzalang
 * @description Buffer的基础用法
 * @Date 2021/6/30 22:58
 */
@Slf4j
public class BasicBuffer {

    public static void main(String[] args) {
        // 创建Buffer，容量为5个int
        IntBuffer intBuffer = IntBuffer.allocate(5);
        // 存放数据
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i + 1);
        }
        // 将Buffer读写转换
        intBuffer.flip();
        // 读取数据
        while (intBuffer.hasRemaining()) {
            log.info("element: {}", intBuffer.get());
        }
    }
}
